package cn.parus.commons.common.Log.controller;

import cn.parus.commons.common.Log.aspect.NoLogging;
import cn.parus.commons.common.Log.entity.LogInfo;
import cn.parus.commons.common.Log.service.LogService;
import cn.parus.commons.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: LogController
 * @Author 潘春兰
 * @Package cn.parus.commons.common.Log.controller
 * @Date 2025/4/2 22:52
 * @description: TODO 日志控制器
 * @Version:
 */
@RestController
@RequestMapping("/log")
@CrossOrigin(origins = "*", maxAge = 3600)
public class LogController {
    @Autowired
    private LogService logService;

    /**
     * 获取日志列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getLogs")
    @NoLogging
    public Result getLogs(@RequestParam (defaultValue = "1") Integer pageNum,
                          @RequestParam (defaultValue = "10") Integer pageSize) {
        Page<LogInfo> logs = logService.getLogs(pageNum, pageSize);
        System.out.println("参数======" + pageNum + pageSize);
        return Result.success(logs);
    }

    /**
     * 根据id删除日志
     * @param logId
     * @return
     */
    @DeleteMapping("/deleteLogById/{logId}")
    public Result deleteLogById(@PathVariable Long logId){
        logService.deleteLogById(logId);
        return Result.success();
    }

    /**
     * 批量删除日志
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteLogBatch")
    public Result deleteLogBatch(@RequestBody List<Long> ids) {
        logService.deleteLogsByIds(ids);
        return Result.success();
    }
}
